package com.nzy.controller;

import com.nzy.entity.Orders;
import com.nzy.mq.producer.MessageProducer;
import com.nzy.mq.producer.OrderMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

@Controller("/mq")
public class MqController {

    @Autowired
    private MessageProducer messageProducer;

    @RequestMapping("/send")
    @ResponseBody
    public String send(Orders orders){
        String id = UUID.randomUUID().toString();
        OrderMessage orderMessage = new OrderMessage();
        orderMessage.setOrderId(orders.getId());
        orderMessage.setSkuId(orders.getSkuId());
        orderMessage.setNumber(orders.getNumber());
        orderMessage.setUserId(orders.getUserId());
        messageProducer.send(orderMessage);
        System.out.println("发送消息:" + orderMessage.toString());
        return "success!";
    }
}
